package com.turing.data.scripts.contract.transfer

import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO


class AfterIfAvailable_30182_10_transfer {

    static List< TaskElementVO.DrawResultVO > doConvert(List< TaskElementVO.DrawResultVO > resultVOs, DependParamsVO dependParams){

        for( drawResultVO in resultVOs ) {
                def childTaskSn = drawResultVO.childTaskSn
                if(null == childTaskSn || childTaskSn == ""){
                    continue
                }
            String modelValue = drawResultVO.text
            def str = ""
            if(modelValue != null && modelValue != ""){
                 str = modelValue.replaceAll("\n", "").replaceAll("\r", "")
            }

            def REGEX_MAP = [
                    "银行活期存款": /.*银行活期存款.*/,
                    "国债"    : /.*国债.*/,
                    "中央银行票据": /.*中央银行票据.*/,
                    "政策性金融债": /.*政策性金融债.*/,
                    "地方政府债券": /.*地方政府债券.*/,
                    "货币市场基金": /.*货币市场基金.*/
            ]

            Map matchMap = [:]

            for (item in REGEX_MAP) {
                if (str =~ "${item.value}") {
                    matchMap.put(str.indexOf("${item.key}"), "${item.key}")
                }
            }

            if (matchMap.size() > 0) {
                StringBuilder sb = new StringBuilder()
                Map sortedMap = matchMap.sort { a, b -> (int) a.key - (int) b.key }
                for (item in sortedMap) {
                    sb.append("${item.value}").append("、")
                }
                drawResultVO.businessValue =  sb.toString().substring(0, sb.length() - 1)
                drawResultVO.type = 1
            } else {
                drawResultVO.businessValue =  ""
                drawResultVO.type = 1
            }

        }

        return resultVOs
    }

}
